﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Network.Bonjour;

namespace AirLib
{
    public class AirplayServiceDiscovery
    {

        public delegate void AirplayServiceFoundDelegate(Network.ZeroConf.IService item);
        public event AirplayServiceFoundDelegate AirplayServiceFound;

        /// <summary>
        /// Initializes a new instance of the <see cref="AirplayServiceDiscovery"/> class.
        /// </summary>
        public AirplayServiceDiscovery()
	    {
            BonjourServiceResolver bsr = new BonjourServiceResolver();
            bsr.ServiceFound += new Network.ZeroConf.ObjectEvent<Network.ZeroConf.IService>(AirplayServiceFoundInternal);
            bsr.Resolve("_airplay._tcp");
        }

        /// <summary>
        /// Airplay Service Found
        /// </summary>
        /// <param name="item">The item.</param>
        private void AirplayServiceFoundInternal(Network.ZeroConf.IService item)
        {
			if(AirplayServiceFound != null)
            {
                AirplayServiceFound(item);
            }
        }
    }    
}
